package com.zerone.pay.gateway;

import com.github.wxpay.sdk.WXPayConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by fire on 2017/9/1.
 */
public class WXPayConfigImpl implements WXPayConfigMore {

	protected static final Logger logger = LoggerFactory
			.getLogger(WXPayConfigImpl.class);

	private String appID;

	private String mchID;

	private String key;

	private String certPath;

	private int httpConnectTimeoutMs;

	private int httpReadTimeoutMs;

	private String token;

	private WXPayConstants.SignType signType;

	private String appSecret;

	public void setToken(String token) {
		this.token = token;
	}


	public void setAppSecret(String appSecret) {
		this.appSecret = appSecret;
	}

	public void setAppID(String appID) {
		this.appID = appID;
	}

	public void setMchID(String mchID) {
		this.mchID = mchID;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public void setCertPath(String certPath) {
		this.certPath = certPath;
	}

	public void setHttpConnectTimeoutMs(int httpConnectTimeoutMs) {
		this.httpConnectTimeoutMs = httpConnectTimeoutMs;
	}

	public void setHttpReadTimeoutMs(int httpReadTimeoutMs) {
		this.httpReadTimeoutMs = httpReadTimeoutMs;
	}

	@Override public String getAppID() {
		return appID;
	}

	@Override public String getMchID() {
		return mchID;
	}

	@Override public String getKey() {
		return key;
	}

	@Override public InputStream getCertStream() {
		try {
			return new ClassPathResource(certPath).getInputStream();
		} catch (IOException e) {
			logger.info("读取微信证书文件未遂",e);
		}
		return null;
	}

	@Override public int getHttpConnectTimeoutMs() {
		return httpConnectTimeoutMs;
	}

	@Override public int getHttpReadTimeoutMs() {
		return httpReadTimeoutMs;
	}

	@Override public String getToken() {
		return token;
	}

	@Override public WXPayConstants.SignType getSignType() {
		return signType;
	}

	@Override public String getAppSecret() {
		return appSecret;
	}

	public void setSignType(WXPayConstants.SignType signType) {
		this.signType = signType;
	}
}
